<template>
  <div>
    <el-container>
      <el-header>
        <span>{{ searchParams.ename }}---相关职位</span>
      </el-header>
    </el-container>
    <div class="graduate-info">
      <div style="display: flex; flex-wrap: wrap">
        <!-- 卡片 -->
        <el-card
          class="search-card"
          v-for="item in positionList"
          :key="item.pid"
        >
          <div slot="header" class="clearfix">
            <span class="card-desc-title">{{ item.name }}</span>
            <el-button
              style="float: right; padding: 3px 0"
              type="text"
              @click="delivery(item.pid, item.hid, item.name)"
              >投递</el-button
            >
          </div>
          <div class="text desc-card">
            <span>公司名称</span>
            <el-divider direction="vertical"></el-divider>
            <span>{{ item.company }}</span>
            <el-divider direction="vertical"></el-divider>
            <span>工作地点</span>
            <el-divider direction="vertical"></el-divider>
            <span>{{ item.paddress }}</span>
            <el-divider direction="vertical"></el-divider>
            <span>招聘人数</span>
            <el-divider direction="vertical"></el-divider>
            <span>{{ item.pnumbers }}</span>
          </div>
          <div class="text">
            <span>学历要求</span>
            <el-divider direction="vertical"></el-divider>
            <span>{{ item.peducation }}</span>
            <el-divider direction="vertical"></el-divider>
            <span style="color: green">薪资水平</span>
            <el-divider direction="vertical"></el-divider>
            <span>{{ item.psalary }}</span>
          </div>
          <div class="text">
            <span style="color: red">相关描述</span>
            <el-divider direction="vertical"></el-divider>
            <span>{{ item.pdesc }}</span>
          </div>
        </el-card>
      </div>
    </div>
    <el-container>
      <el-footer>
        <div>
          <span>专注于互联网校招</span>
        </div>
      </el-footer>
    </el-container>
  </div>
</template>

<script>
export default {
  name: "RecommendGraduateposition",

  data() {
    return {
      searchParams: "",
      positionList: [],
      delivaryObj: {
        pid: 0,
        hid: 0,
        name: "",
        gname: "",
      },
      resumeObj: {
        rid: 0,
        gid: 0,
        gname: "",
        schoolname: "",
        address: "",
        city: "",
        email: "",
        identify: "",
        advantage: "",
        position: "",
        salary: 0,
        sex: "",
        age: 0,
        birthday: new Date(),
      },
    };
  },

  mounted() {
    this.getSid();
    this.loadList();
    this.loadResume();
  },

  methods: {
    // 获取参数
    getSid() {
      this.searchParams = this.$route.params;
    },
    // 加载数据
    loadList() {
      this.$axios
        .post("/position/loadByName", this.searchParams)
        .then((res) => {
          if (res.data.result != null) {
            this.positionList = res.data.result;
          } else {
            return;
          }
        })
        .catch((error) => {
          console.log(error);
          this.$message({
            message: "系统错误!!!",
            type: "error",
          });
        });
    },
    // 判断有无简历
    loadResume() {
      this.$axios
        .post("/resume/queryResumeByGid")
        .then((res) => {
          if (res.data.result != null) {
            this.resumeObj = res.data.result;
          } else {
            return;
          }
        })
        .catch((error) => {
          console.log(error);
          this.$message({
            message: "系统错误!!!",
            type: "error",
          });
        });
    },
    // 投递
    delivery(pid, hid, name) {
      this.delivaryObj.pid = pid;
      this.delivaryObj.hid = hid;
      this.delivaryObj.name = name;
      this.delivaryObj.gname = this.resumeObj.gname;
      if (this.resumeObj.rid === 0) {
        this.$message({
          message: "简历未填写无法投递",
          type: "error",
        });
        return;
      }
      // 发送投递请求
      this.$axios
        .post("/delivery/deliveryResume", this.delivaryObj)
        .then((res) => {
          var response = res.data.desc;
          if (response === "投递失败") {
            this.$message({
              message: "投递失败",
              type: "error",
            });
            return;
          } else if (response === "已经投递") {
            this.$message({
              message: "已经透过,无需再投",
              type: "error",
            });
            return;
          } else if (response === "投递成功") {
            this.$message({
              message: "投递成功",
              type: "success",
            });
          }
        })
        .catch((error) => {
          console.log(error);
          this.$message({
            message: "系统错误!!!",
            type: "error",
          });
        });
    },
  },
};
</script>

<style scoped>
.el-header {
  background-color: #409eff;
  color: white;
  line-height: 60px;
}

.el-footer {
  background-color: #409eff;
  color: white;
  line-height: 60px;
}

.el-footer div {
  margin-left: 43%;
}

.graduate-info {
  margin-top: 10px;
  margin-bottom: 10px;
  height: 480px;
  background: whitesmoke;
  /* background-image: url(https://img2.baidu.com/it/u=1704860233,2657475479&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=250);
    background-size: 1355px 480px; */
  overflow: auto;
}

.text {
  font-size: 14px;
  text-align: left;
  margin-bottom: 15px;
  margin-left: 1px;
}

.clearfix-span {
  margin-left: 0px;
  margin-right: 180px;
  color: red;
}

.search-card {
  margin-top: 10px;
  margin-left: 5px;
  padding: 0px;
  width: 435px;
  height: 210px;
}

.card-desc-title {
  color: orange;
  margin-right: 200px;
}

.flex-card {
  display: flex;
  flex-wrap: wrap;
}
</style>
